from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponseRedirect
from gironimo.gallery.models import Album


def index(request):
    '''
        Shows all available galleries
    '''
    galleries = Album.objects.all()
    return render_to_response('index.html',{
    'galleries': galleries}, context_instance=RequestContext(request))

def contact(request):
    from gironimo.forms import ContactForm
    
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            from_email = form.cleaned_data['email']
            subject = form.cleaned_data['topic']
            message = form.cleaned_data['message']
            name = form.cleaned_data['name']
            
            recipients = ['kontakt@gironimo.org']
            
            from django.core.mail import send_mail
            send_mail(subject, message, from_email, recipients)
            return HttpResponseRedirect('/kontakt/danke/')
    else:
        form = ContactForm()
    
    return render_to_response('contact.html', {
    'form': form}, context_instance=RequestContext(request))

def contact_thx(request):
    return render_to_response('contact_thx.html', {
    }, context_instance=RequestContext(request))

